<%-- 
    Document   : resolveExercise
    Created on : 29-feb-2012, 23:13:18
    Author     : CarmaZone
--%>

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@ page language="java"%>
<%@ taglib uri="http://struts.apache.org/tags-bean" prefix="bean" %>
<%@ taglib uri="http://struts.apache.org/tags-html" prefix="html" %>
<%@ taglib uri="http://struts.apache.org/tags-logic" prefix="logic" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>

<head>
    <title></title>
    <link rel="stylesheet" href="./JS/styles/sunburst.css">
    <meta charset="utf-8">
    <style type="text/css">
        #t1 { width: 100%;}
        tr { vertical-align: top; }
        address { margin-top: 4em; }
    </style>
    <script src="./JS/highlight.pack.js"></script>
    <script>hljs.initHighlightingOnLoad();</script>
</head>
<body>
    <b><bean:message key="list.sender"/>:&nbsp</b>${ej.usuarios.alias}<br>
    <b><bean:message key="titulo.txt"/></b>:&nbsp${ej.titulo}<br>
    <b><bean:message key="descripcion.txt"/></b>:&nbsp${ej.descripcion}<br><br>
    <table width="100%">
        <html:form action="/resolveExercise?idres=${idRes}&idej=${ej.idejercicio}">
            <tr>
                <td><b><bean:message key="codigo.txt"/></b><font style="color: red"><html:errors/></font><br></td>
            </tr>
            <tr>                                
                <td><textarea rows="20" cols="40" id="t1" name="codigoFuente" onkeyup="doIt()"></textarea></td>
            </tr>
        </table>
        <table width="98%">
            <tr>
                <td>
                    <html:submit><bean:message key="button.submit"/></html:submit>
                    <html:reset><bean:message key="button.delete"/></html:reset>
                    <script type="text/javascript">
                        var langSelectorHtml = '<label>Language <select id="langSelector">';
                        langSelectorHtml += '<option value="">Auto</option>';
                        for (var i in hljs.LANGUAGES) {
                            if (hljs.LANGUAGES.hasOwnProperty(i))
                                langSelectorHtml += '<option value=\"'+i+'\">'+i.charAt(0).toUpperCase()+i.substr(1)+'</option>';
                        }
                        langSelectorHtml += '</select></label>';
                        document.write(langSelectorHtml);
                    </script>
                </td>
            </tr>
        </html:form>
    </table>
    <div id="highlight-view"></div>  

    <script type="text/javascript">
        String.prototype.escape = function() {
            return this.replace(/&/gm, '&amp;').replace(/</gm, '&lt;').replace(/>/gm, '&gt;');
        }

        function doIt() {
            var viewDiv = document.getElementById("highlight-view");
            var t1 = document.getElementById("t1");
            var selector = document.getElementById("langSelector");
            var selectedLang = selector.options[selector.selectedIndex].value.toLowerCase();
            if(selectedLang) {
                viewDiv.innerHTML = '<pre><code class="'+selectedLang+'">'+t1.value.escape()+"</code></pre>";
            } else { // try auto
                viewDiv.innerHTML = '<pre><code>' + t1.value.escape() + "</code></pre>";
            }
            hljs.highlightBlock(viewDiv.firstChild.firstChild);
        }
    </script>
</body>